package com.hyq.market.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import com.hannesdorfmann.mosby.mvp.MvpActivity;
import com.hannesdorfmann.mosby.mvp.MvpPresenter;
import com.hannesdorfmann.mosby.mvp.MvpView;
import com.hyq.market.utils.MPermissionUtils;

import java.io.Serializable;

import butterknife.ButterKnife;
import butterknife.Unbinder;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;

/**
 * Created by LS on 2017/5/24 0024.
 * 不需要实现MVP的基类
 *
 * T 需要接收的可序列化对象类型
 */

public abstract class AbsAct<V extends MvpView, P extends IPersenter<V>> extends MvpActivity<V, P> {

    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /**
         *  需要在调用{@link BaseMvpAct#setContentView(int)}之前调用
         */
        setStatueBar();
        setContentView(getLayoutId());
        unbinder = ButterKnife.bind(this);
        initEvent();

    }

    protected boolean getBooleanExtra(String key) {
        Bundle extras = getIntent().getExtras();
        return extras != null && extras.getBoolean(key);
    }

    /**
     * 需要改变状态栏颜色重写此方法
     *
     */
    protected void setStatueBar() {
        //RxBarUtils.setStatusBarColor(this, R.color.colorPrimary);
    }

    protected abstract int getLayoutId();

    protected abstract void initEvent();
    /**
     * 标题左边点击事件，默认关闭，需要特殊处理重写{@link #onLeftClick()}
     */

    /**
     * 标题左边点击事件，需要特殊处理重写此方法
     * {@link #finish()}
     */
    public void onLeftClick() {
        finish();
    }

    /**
     * 标题右边点击事件，需要点击重写此方法
     */
    public void onRightClick(View view) {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(unbinder != null){
            unbinder.unbind();
            unbinder = null;
        }
    }

//    @Override
//    public void finish() {
//        super.finish();
//        overridePendingTransition(R.anim.left_in, R.anim.right_out);
//    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        MPermissionUtils.onRequestPermissionsResult(requestCode, permissions, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }


    public void showMsg(String  msg) {

        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
    }
}
